package com.ruoyi.web.controller.business;

import com.ruoyi.business.domain.TSmjGoodList;
import com.ruoyi.business.service.ITSmjGoodListService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 售卖机物品信息Controller
 *
 * @author admin
 * @date 2024-10-24
 */
@Controller
@RequestMapping("/business/smjGoodList")
public class TSmjGoodListController extends BaseController
{
    private final Logger logger = LoggerFactory.getLogger(getClass());

    private String prefix = "business/smjGoodList";

    @Autowired
    private ITSmjGoodListService tSmjGoodListService;

    @RequiresPermissions("business:smjGoodList:view")
    @GetMapping()
    public String smjGoodList()
    {
        return prefix + "/smjGoodList";
    }

    /**
     * 查询售卖机物品信息列表
     */
    @RequiresPermissions("business:smjGoodList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSmjGoodList tSmjGoodList)
    {
        startPage();
        List<TSmjGoodList> list = tSmjGoodListService.selectTSmjGoodListList(tSmjGoodList);
        return getDataTable(list);
    }

    /**
     * 导出售卖机物品信息列表
     */
    @RequiresPermissions("business:smjGoodList:export")
    @Log(title = "售卖机物品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSmjGoodList tSmjGoodList)
    {
        List<TSmjGoodList> list = tSmjGoodListService.selectTSmjGoodListList(tSmjGoodList);
        ExcelUtil<TSmjGoodList> util = new ExcelUtil<TSmjGoodList>(TSmjGoodList.class);
        return util.exportExcel(list, "smjGoodList");
    }

    /**
     * 新增售卖机物品信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存售卖机物品信息
     */
    @RequiresPermissions("business:smjGoodList:add")
    @Log(title = "售卖机物品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSmjGoodList tSmjGoodList)
    {
        return toAjax(tSmjGoodListService.insertTSmjGoodList(tSmjGoodList));
    }

    /**
     * 修改售卖机物品信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TSmjGoodList tSmjGoodList = tSmjGoodListService.selectTSmjGoodListById(id);
        mmap.put("tSmjGoodList", tSmjGoodList);
        return prefix + "/edit";
    }

    /**
     * 修改保存售卖机物品信息
     */
    @RequiresPermissions("business:smjGoodList:edit")
    @Log(title = "售卖机物品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSmjGoodList tSmjGoodList)
    {
        return toAjax(tSmjGoodListService.updateTSmjGoodList(tSmjGoodList));
    }

    /**
     * 删除售卖机物品信息
     */
    @RequiresPermissions("business:smjGoodList:remove")
    @Log(title = "售卖机物品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tSmjGoodListService.deleteTSmjGoodListByIds(ids));
    }

    @Log(title = "用户收款号状态变更", businessType = BusinessType.UPDATE)
    @RequiresPermissions("business:smjGoodList:edit")
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(TSmjGoodList tSmjGoodList) {
        TSmjGoodList newtTSmjGoodList = tSmjGoodListService.selectTSmjGoodListById(tSmjGoodList.getId());
        newtTSmjGoodList.setGoodStatus(tSmjGoodList.getGoodStatus());
        return toAjax(tSmjGoodListService.updateTSmjGoodList(newtTSmjGoodList));
//        return toAjax(tNginxInfoService.updateTNginxInfo(tNginxInfo));
    }
}
